﻿const express = require('express');
const bodyParser = require('body-parser');

const app = express();
const urlencodedParser = bodyParser.urlencoded({ extended:false});

app.set('view engine','ejs');

app.use('/assets', express.static('assets'));

app.get('/',(req,res)=>{
    //res.send('home page');
    //res.sendFile(__dirname + '/index.html')
    res.render('index');
});

app.get('/about',(req,res)=>{
    //res.send('about page')
    // res.sendFile(__dirname + '/about.html')
    res.render('about',{ qs: req.query });
});

app.post('/about',urlencodedParser,(req,res)=>{
    console.log(req.body);
    res.render('about-success',{data:req.body})
});

app.get('/profile/:name',(req,res)=>{
   //res.send('Profile id is:'+ req.params.id);
    const data = {age:30,job:'developer',friends:['sha','he','liu']}
    res.render('profile',{ person:req.params.name,data });
});

app.listen(3000)